import { tableData1, tableData2, tableData3, tableData4, tableData5 } from './js/table'
import {
    newRecordOptions
} from './js/myCharts'
export default {
    name: "ItemManage",
    data () {
        return {
            imgList: [
                {
                    id: 0,
                    icon: require('@/assets/images/search.png'),
                    iconActive: require('@/assets/images/search-active.png')
                }, {
                    id: 1,
                    icon: require('@/assets/images/import.png'),
                    iconActive: require('@/assets/images/import-active.png')
                }, {
                    id: 2,
                    icon: require('@/assets/images/export.png'),
                    iconActive: require('@/assets/images/export-active.png')
                }, {
                    id: 3,
                    icon: require('@/assets/images/statistics.png'),
                    iconActive: require('@/assets/images/statistics-active.png')
                }, {
                    id: 4,
                    icon: require('@/assets/images/delete.png'),
                    iconActive: require('@/assets/images/delete-active.png')
                }
            ], // 图标集合
            navList: [
                { id: 0, name: '全部' },
                /*{ id: 1, name: '待审核' },*/
                { id: 2, name: '未开始' },
                { id: 3, name: '进行中' },
                { id: 4, name: '已结束' }
            ], // 导航集合
            hoverIndex: -1, // 头部当前hover图标
            currentNav: '', // 当前导航
            currentTable: '', // 当前table
            // 列表数据
            tableData1: [],
            tableData2: [],
            tableData3: [],
            tableData4: [],
            tableData5: [],
            uploadDialogVisible: false, // 上传Excel弹框是否显示
            exportDialogVisible: false, // 导出Excel弹框是否显示
            // 导出弹框:选中导出字段
            allChecked: ["项目状态", "项目名称", "项目编号", "开始日期", "结束日期", '资金来源', '项目资金', '项目经理', "拥有者", "创建人", "创建时间", "最近修改时间"],
            // 导出弹框:全部导出字段
            checkList: ["项目状态", "项目名称", "项目编号", "开始日期", "结束日期", '资金来源', '项目资金', '项目经理', "拥有者", "创建人", "创建时间", "最近修改时间"],
            // 导出弹框:是否全选
            checkAll: true,
            // 导出弹框:checkbox 的不确定状态
            isIndeterminate: false,
            statisticsDrawer: false, // 统计抽屉,
            createDialogVisible: false, // 新增记录弹框是否显示
            newRecordForm: {
                itemStatus: '',
                itemName: '',
                itemNum: '',
                startDate: '',
                endDate: '',
                source: '',
                itemFunds: '',
                itemManager: '',
                relatedTasks: '',
                budgetMgt: ''
            }, // 新建记录表单对象
            detailDialogVisible: false, // 详情弹框是否显示
            rowValueForm: {
                itemStatus: '',
                itemName: '',
                itemNum: '',
                startDate: '',
                endDate: '',
                source: '',
                itemFunds: '',
                itemManager: '',
                relatedTasks: '',
                budgetMgt: '',
                owner: '',
                creater: '',
                createTime: '',
                updateTime: ''
            }, // table行详情表单对象
            titles: ["任务名称", "状态", "任务描述", "工时估算"], // 详情弹框：右侧table头部
            lines: [
            	{taskName:"投标",status:"进行中",discribe:"",time:"3小时"},
            	{taskName:"预定后勤资源",status:"未开始",discribe:"",time:"5小时"},
            	{taskName:"邀请客户",status:"进行中",discribe:"",time:"4小时"},
            	{taskName:"招标",status:"已结束",discribe:"",time:"6小时"}
            ], // 详情弹框：右侧table内容
            checked: false, // 详情弹框：是否保存后新增下一条
        }
    },
    computed: {
        newRecordOptions () {
            return newRecordOptions
        }
    },
    mounted () {
        this.tableData1 = tableData1;
        this.tableData2 = tableData2;
        this.tableData3 = tableData3;
        this.tableData4 = tableData4;
        this.tableData5 = tableData5
    },
    methods: {
        /**
         * 鼠标移出
         * @param index
         */
        mouseLeave: function (index) {
            this.hoverIndex = index
        },
        /**
         * 鼠标移入
         * @param index
         */
        mouseEnter: function (index) {
            this.hoverIndex = index
        },
        /**
         * 头部图标点击时触发
         * @param id
         */
        iconClick (id) {
            if (id === 1) {
                this.uploadDialogVisible = true
            } else if (id === 2) {
                this.exportDialogVisible = true
            } else if (id === 3) {
                this.statisticsDrawer = true
                this.$nextTick(() => {
                    this.initCharts()
                })
            } else if (id === 4) {
                this.$confirm('您确定要删除这条记录?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                        if (this.currentNav == 1) {
                            this.tableData2.splice(0, 1);
                        } else if (this.currentNav == 2) {
                            this.tableData3.splice(0, 1);
                        } else if (this.currentNav == 3) {
                            this.tableData4.splice(0, 1);
                        } else if (this.currentNav == 4) {
                            this.tableData5.splice(0, 1);
                        } else {
                            this.tableData1.splice(0, 1);
                        }
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    }
                ).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        },
        /**
         * 导航切换
         * @param index
         */
        switchNav (index) {
            this.currentNav = index
        },
        /**
         * 点击某行数据触发显示行详情
         * @param val
         */
        handleRow (val) {
            this.rowValueForm = val;
            this.detailDialogVisible = true;
        },
        /**
         * 导入文件
         */
        uploadExcel () {
            // if (this.currentNav == 1) {
            //     this.tableData2 = tableData5;
            // } else if (this.currentNav == 2) {
            //     this.tableData3 = tableData6;
            // } else {
            //     this.tableData1 = tableData4;
            // }
            // this.uploadDialogVisible = false;
        },
        /**
         * 导出弹框：导出字段全选框改变时触发
         * @param val
         */
        handleCheckAllChange (val) {
            this.allChecked = val ? this.checkList : [];
        },
        /**
         * 导出弹框：导出字段checkbox改变时触发
         * @param value
         */
        handleCheckedFieldsChange (value) {
            let checkedCount = value.length;
            this.checkAll = checkedCount === this.checkList.length;
            this.isIndeterminate = checkedCount > 0 && checkedCount < this.checkList.length;
        },
        /**
         * 统计：初始化图表
         */
        initCharts () {
            // 每日新增项目图表
            let newRecordChart = this.$echarts.init(document.getElementById('newRecord'))
            newRecordChart.setOption(this.newRecordOptions)
        },
        /**
         * 新增项目
         */
        creatNew () {
            this.createDialogVisible = true;
        },
    }
}
